package com.jxud.enums;

public enum OrderStatus {

    PENDING(0, "已识别"),
    PROCESSING(1, "备货中"),
    SHIPPED(2, "已发货"),
    CANCELLED(3, "已取消"),
    COMPLETED(4, "已完成");

    private final int code;
    private final String desc;

    OrderStatus(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    // 根据code获取枚举对象
    public static OrderStatus fromCode(int code) {
        for (OrderStatus status : OrderStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的订单状态码: " + code);
    }

    // 重写toString，方便打印查看
    @Override
    public String toString() {
        return desc;
    }
}
